# from __future__ import absolute_import, unicode_literals
# import os
# from celery import Celery
#
# # set the default Django settings module for the 'celery' program.
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
#
# app = Celery('proj')
#
# # Using a string here means the worker doesn't have to serialize
# # the configuration object to child processes.
# # - namespace='CELERY' means all celery-related configuration keys
# #   should have a `CELERY_` prefix.
# app.config_from_object('django.conf:settings', namespace='CELERY')
#
# # Load task modules from all registered Django app configs.
# app.autodiscover_tasks()
#
#
# @app.task(bind=True)
# def debug_task(self):
#     print('Request: {0!r}'.format(self.request))

# 1. 导入 celery模块
import os
import sys


BASE_DIR = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(BASE_DIR,'../'))
sys.path.insert(0, os.path.join(BASE_DIR,'../meiduo_mall/'))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'meiduo_mall.dev')


from celery import Celery

# 2. 实例化一个 celery 对象, 要给一个名字, 告诉他 任务发布到哪里, 结果保存在哪
# app = Celery('calculation', broker='redis://127.0.0.1:6379/14', backend='redis://127.0.0.1:6379/15')
app = Celery('meiduo_mall')

# 2.1 加载配置
app.config_from_object('celery_tasks.config', namespace='CELERY')


# 3. 告诉celery对象可以执行什么工作
# @app.task
# def add(x, y):
#     print(x + y)
#     return x + y
#
#
# @app.task
# def sub(x, y):
#     print(x - y)
#     return x - y

# 通过 app.autodiscover_tasks() 方法加载任务模块 等同于 使用 @app.task
app.autodiscover_tasks(['celery_tasks.tasks.calculation','celery_tasks.tasks.sms','celery_tasks.tasks.email'])



# 4. 启动worker, 用来处理任务
# celery -A proj worker -l info
# celery -A celery_tasks.main worker -l info
